package com.zmzncs.shop.module.shop.service.impl;

import org.springframework.beans.BeanUtils;
import com.zmzncs.shop.module.shop.pojo.shopticketfile.*;
import com.zmzncs.shop.module.shop.mapper.ShopTicketFileMapper;
import com.zmzncs.shop.module.shop.service.ShopTicketFileService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 高博文
 * @since 2021-05-25
 */
@Service
public class ShopTicketFileServiceImpl extends ServiceImpl<ShopTicketFileMapper, ShopTicketFile> implements ShopTicketFileService {

    @Autowired
    private ShopTicketFileMapper shopTicketFileMapper;

    /**
    * 分页
    */
    @Override
    public IPage<ShopTicketFileDTO> page(ShopTicketFileSearchForm form){
        IPage<ShopTicketFileDTO> iPage = shopTicketFileMapper.list(form.getPage());

        return iPage;
    }

    /**
    * 添加
    */
    @Override
    @Transactional
    public void add(ShopTicketFileAddForm form){
        ShopTicketFile shopTicketFile = new ShopTicketFile();
        BeanUtils.copyProperties(form, shopTicketFile);

        shopTicketFileMapper.insert(shopTicketFile);
    }

    /**
    * 删除
    */
    @Override
    @Transactional
    public void delete(Long id){
        ShopTicketFile shopTicketFile = new ShopTicketFile();
        shopTicketFile.setId(id);
        shopTicketFile.setIsDeleted(1);

        shopTicketFileMapper.updateById(shopTicketFile);
    }

    /**
    * 修改
    */
    @Override
    @Transactional
    public void update(ShopTicketFileUpdateForm form){
        ShopTicketFile shopTicketFile = new ShopTicketFile();
        BeanUtils.copyProperties(form, shopTicketFile);

        shopTicketFileMapper.updateById(shopTicketFile);
    }

    /**
    * 详情
    */
    @Override
    public ShopTicketFileDTO getById(Long id){
        ShopTicketFileDTO shopTicketFileDTO = shopTicketFileMapper.getById(id);

        return shopTicketFileDTO;
    }

}
